home *** CD-ROM | disk | FTP | other *** search
- #include<A4Stuff.h>
- #include<MixedMode.h>
- #include<Gestalt.h>
-
- #include<stdio.h>
- #include<stdarg.h>
-
- #define KeyDown(key) (( (keys)[key>>3] >> (key & 7) ) & 1)
-
- enum{
- stdBitsProcInfo = ( kPascalStackBased |
- STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(PixMap *))) |
- STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Rect *))) |
- STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(Rect *))) |
- STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(short))) |
- STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(RgnHandle)))
- )
- };
-
- void main(void);
- pascal OSErr GestaltSelector(OSType selector, long *response);
- pascal void NewStdBits(PixMap *srcMap, Rect *srcRect, Rect *destRect, short tMode, RgnHandle maskRgn);
-
- void Invert(Rect *);
- void Dim(Rect *);
- void Blur(Rect *);
- void Apple2(Rect *);
- void Flip(Rect *);
- void NoBlue(Rect *);
- void Trace(Rect *);
- void Right(Rect *src);
- void Left(Rect *src);
-
- void dprintf(char *format, ...);
-
- RoutineDescriptor MainRD = BUILD_ROUTINE_DESCRIPTOR(kCStackBased, main);
- GWorldPtr gBraveNewGWorld;
- RoutineDescriptor *gStdBitsAddr;
- long gFiltersToUse = 0;
-
- void main(void)
- {
- // SelectorFunctionProcPtr gestaltProc;
- UniversalProcPtr theProcPtr;
- THz theZone;
- OSErr err;
- PixMapHandle myPMap;
-
- InitGraf(&qd.thePort);
-
- theZone = GetZone();
- SetZone(SystemZone());
-
- err = NewGWorld(&gBraveNewGWorld, 32, &qd.screenBits.bounds, nil, nil, 0);
-
- if ((err) || (gBraveNewGWorld == nil))
- {
- dprintf("Couldn't allocate GWorld, error %hd", (short)err);
- SetZone(theZone);
- return;
- }
- myPMap = GetGWorldPixMap(gBraveNewGWorld);
- LockPixels(myPMap);
-
- DetachResource( GetResource('INIT',23) );
-
- gStdBitsAddr = NGetTrapAddress(_StdBits, ToolTrap);
-
- theProcPtr = NewRoutineDescriptor( (ProcPtr)NewStdBits,
- stdBitsProcInfo,
- GetCurrentArchitecture() );
-
- NSetTrapAddress(theProcPtr, _StdBits, ToolTrap);
-
- NewSelectorFunctionProc(GestaltSelector);
-
- err = NewGestalt('AltS', NewSelectorFunctionProc(GestaltSelector));
- if (err) {
- dprintf("Couldn't newgestalt, error %hd", (short)err);
- SetZone(theZone);
- return;
- }
-
- SetZone(theZone);
- }
-
- pascal void NewStdBits(PixMap *srcMap, Rect *srcRect, Rect *destRect, short tMode, RgnHandle maskRgn)
- {
- THz theZone;
- Rect foozRect;
- GWorldPtr oldGraf;
- GDHandle oldGD;
- int i;
-
- theZone = GetZone();
- SetZone(SystemZone());
-
- foozRect = *srcRect;
- OffsetRect(&foozRect, -foozRect.left, -foozRect.top);
-
- if(foozRect.right < 1024 && foozRect.bottom < 768 && gFiltersToUse) {
- GetGWorld(&oldGraf, &oldGD);
- SetGWorld(gBraveNewGWorld, nil);
-
- CALL_FIVE_PARAMETER_UPP( gStdBitsAddr, stdBitsProcInfo, srcMap, srcRect, &foozRect, srcCopy, nil);
-
- for(i=0;i<32;i++)
- {
- if(gFiltersToUse & 1 << i)
- {
- switch(i)
- {
- case 0:
- Dim(&foozRect);
- break;
- case 1:
- Trace(&foozRect);
- break;
- case 2:
- Flip(&foozRect);
- break;
- case 3:
- Invert(&foozRect);
- break;
- case 4:
- Blur(&foozRect);
- break;
- case 5:
- Apple2(&foozRect);
- break;
- default:
- break;
- }
- }
- }
-
- SetGWorld(oldGraf, oldGD);
-
- CALL_FIVE_PARAMETER_UPP( gStdBitsAddr, stdBitsProcInfo, *GetGWorldPixMap(gBraveNewGWorld), &foozRect, destRect, tMode, maskRgn);
-
- } else {
- CALL_FIVE_PARAMETER_UPP( gStdBitsAddr, stdBitsProcInfo, srcMap, srcRect, destRect, tMode, maskRgn);
- }
-
- SetZone(theZone);
- }
-
- pascal OSErr GestaltSelector(OSType, long *response) {
- *response = (long) &gFiltersToUse;
- return noErr;
- }
-
- void Invert(Rect *foo) {
- InvertRect(foo);
- }
-
- void Dim(Rect *baz) {
- PixMapHandle bar = GetGWorldPixMap(gBraveNewGWorld);
- unsigned long rbytes = bar[0]->rowBytes & 0x3FFF;
- Rect foo = bar[0]->bounds;
- Ptr data = GetPixBaseAddr(GetGWorldPixMap(gBraveNewGWorld));
- long x, y;
- unsigned long *pixelptr;
-
- if(!data) {
- DebugStr("\pthe pixbaseaddr of our gworld is nil");
- return;
- }
-
- for(y = baz->top; y < baz->bottom; y++) {
- for(x = baz->left; x < baz->right; x++) {
- pixelptr = (unsigned long*)(data + (y * rbytes) + (x * 4));
- *pixelptr -= (*pixelptr & 0xF0F0F0F0) >> 4;
- // *(unsigned long*)(data + (y * rbytes) + (x * 4)) >>= 1;
- }
- }
- }
-
- void Blur(Rect *baz) {
- PixMapHandle bar = GetGWorldPixMap(gBraveNewGWorld);
- unsigned long rbytes = (bar[0]->rowBytes & 0x3FFF) >> 2;
- Ptr data = GetPixBaseAddr(GetGWorldPixMap(gBraveNewGWorld));
- long x, y;
- unsigned long *pixelptr;
-
- if(!data) {
- DebugStr("\pthe pixbaseaddr of our gworld is nil");
- return;
- }
-
- pixelptr = (unsigned long*)(data + (baz->top * (rbytes<<2)) + (baz->left * 4));
- *pixelptr = ((*pixelptr & 0xFEFEFEFE) >> 1) +
- ( ( (*(pixelptr + 1) & 0xFCFCFCFC) | 0x04040404) >> 2) +
- ( ( (*(pixelptr + rbytes) & 0xFCFCFCFC) | 0x04040404) >> 2);
-
- pixelptr = (unsigned long*)(data + ((baz->bottom-1) * (rbytes<<2)) + (baz->left * 4));
- *pixelptr = ((*pixelptr & 0xFEFEFEFE) >> 1) +
- ( ( (*(pixelptr + 1) & 0xFCFCFCFC) | 0x04040404) >> 2) +
- ( ( (*(pixelptr - rbytes) & 0xFCFCFCFC) | 0x04040404) >> 2);
-
- pixelptr = (unsigned long*)(data + (baz->top * (rbytes<<2)) + ((baz->right-1) * 4));
- *pixelptr = ((*pixelptr & 0xFEFEFEFE) >> 1) +
- ( ( (*(pixelptr - 1) & 0xFCFCFCFC) | 0x04040404) >> 2) +
- ( ( (*(pixelptr + rbytes) & 0xFCFCFCFC) | 0x04040404) >> 2);
-
- pixelptr = (unsigned long*)(data + ((baz->bottom-1) * (rbytes<<2)) + ((baz->right-1) * 4));
- *pixelptr = ((*pixelptr & 0xFEFEFEFE) >> 1) +
- ( ( (*(pixelptr - 1) & 0xFCFCFCFC) | 0x04040404) >> 2) +
- ( ( (*(pixelptr - rbytes) & 0xFCFCFCFC) | 0x04040404) >> 2);
-
- for(x = baz->left + 1; x < baz->right - 1; x++) {
- pixelptr = (unsigned long*)(data + (baz->top * (rbytes<<2)) + (x * 4));
- *pixelptr = ((*pixelptr & 0xFEFEFEFE) >> 1) +
- ( ( (*(pixelptr - 1) & 0xF8F8F8F8) | 0x08080808) >> 3) +
- ( ( (*(pixelptr + 1) & 0xF8F8F8F8) | 0x08080808) >> 3) +
- ( ( (*(pixelptr + rbytes) & 0xFCFCFCFC) | 0x04040404) >> 2);
-
- pixelptr = (unsigned long*)(data + ((baz->bottom-1) * (rbytes<<2)) + (x * 4));
- *pixelptr = ((*pixelptr & 0xFEFEFEFE) >> 1) +
- ( ( (*(pixelptr - 1) & 0xF8F8F8F8) | 0x08080808) >> 3) +
- ( ( (*(pixelptr + 1) & 0xF8F8F8F8) | 0x08080808) >> 3) +
- ( ( (*(pixelptr - rbytes) & 0xFCFCFCFC) | 0x04040404) >> 2);
- }
-
- for(y = baz->top + 1; y < baz->bottom - 1; y++) {
- pixelptr = (unsigned long*)(data + (y * (rbytes<<2)) + (baz->left * 4));
- *pixelptr = ((*pixelptr & 0xFEFEFEFE) >> 1) +
- ( ( (*(pixelptr + 1) & 0xFCFCFCFC) | 0x04040404) >> 2) +
- ( ( (*(pixelptr - rbytes) & 0xF8F8F8F8) | 0x08080808) >> 3) +
- ( ( (*(pixelptr + rbytes) & 0xF8F8F8F8) | 0x08080808) >> 3);
-
- pixelptr = (unsigned long*)(data + (y * (rbytes<<2)) + ((baz->right-1) * 4));
- *pixelptr = ((*pixelptr & 0xFEFEFEFE) >> 1) +
- ( ( (*(pixelptr - 1) & 0xFCFCFCFC) | 0x04040404) >> 2) +
- ( ( (*(pixelptr - rbytes) & 0xF8F8F8F8) | 0x08080808) >> 3) +
- ( ( (*(pixelptr + rbytes) & 0xF8F8F8F8) | 0x08080808) >> 3);
- }
-
- for(y = baz->top + 1; y < baz->bottom - 1; y++) {
- for(x = baz->left + 1; x < baz->right - 1; x++) {
- pixelptr = (unsigned long*)(data + (y * (rbytes<<2)) + (x * 4));
- *pixelptr = ((*pixelptr & 0xFEFEFEFE) >> 1) +
- ( ( (*(pixelptr - 1) & 0xF8F8F8F8) | 0x08080808) >> 3) +
- ( ( (*(pixelptr + 1) & 0xF8F8F8F8) | 0x08080808) >> 3) +
- ( ( (*(pixelptr - rbytes) & 0xF8F8F8F8) | 0x08080808) >> 3) +
- ( ( (*(pixelptr + rbytes) & 0xF8F8F8F8) | 0x08080808) >> 3);
- }
- }
- }
-
- void Apple2(Rect *baz) {
- PixMapHandle bar = GetGWorldPixMap(gBraveNewGWorld);
- unsigned long rbytes = bar[0]->rowBytes & 0x3FFF;
- Ptr data = GetPixBaseAddr(GetGWorldPixMap(gBraveNewGWorld));
- long x, y;
- unsigned long *pixelptr;
- unsigned short quux;
-
- if(!data) {
- DebugStr("\pthe pixbaseaddr of our gworld is nil");
- return;
- }
-
- for(y = baz->top; y < baz->bottom; y++) {
- for(x = baz->left; x < baz->right; x++) {
- pixelptr = (unsigned long*)(data + (y * rbytes) + (x * 4));
- quux = ((unsigned char*)pixelptr)[1];
- quux += ((unsigned char*)pixelptr)[3];
- quux >>= 1;
- ((unsigned char*)pixelptr)[1] = ((unsigned char*)pixelptr)[3] = quux;
- }
- }
- }
-
- void Flip(Rect *baz) {
- PixMapHandle bar = GetGWorldPixMap(gBraveNewGWorld);
- unsigned long rbytes = bar[0]->rowBytes & 0x3FFF;
- Ptr data = GetPixBaseAddr(GetGWorldPixMap(gBraveNewGWorld));
- long x, y;
- unsigned long *top, *bottom;
- unsigned long temp;
-
- if(!data) {
- DebugStr("\pthe pixbaseaddr of our gworld is nil");
- return;
- }
-
- for(y = baz->top; y < baz->bottom - ((baz->bottom - baz->top + 1)>>1); y++) {
- for(x = baz->left; x < baz->right; x++) {
- top = (unsigned long*)(data + (y * rbytes) + (x * 4));
- bottom = (unsigned long*)(data + ((baz->bottom - y - 1) * rbytes) + (x * 4));
- temp = *bottom;
- *bottom = *top;
- *top = temp;
- }
- }
- }
-
- void NoBlue(Rect *baz) {
- PixMapHandle bar = GetGWorldPixMap(gBraveNewGWorld);
- unsigned long rbytes = bar[0]->rowBytes & 0x3FFF;
- Ptr data = GetPixBaseAddr(GetGWorldPixMap(gBraveNewGWorld));
- long x, y;
- unsigned long *pixelptr;
- short temp;
-
- if(!data) {
- DebugStr("\pthe pixbaseaddr of our gworld is nil");
- return;
- }
-
- for(y = baz->top; y < baz->bottom; y++) {
- for(x = baz->left; x < baz->right; x++) {
- pixelptr = (unsigned long*)(data + (y * rbytes) + (x * 4));
- temp = ((unsigned char*)pixelptr)[1] + ((unsigned char*)pixelptr)[2];
- ((unsigned char*)pixelptr)[3] = temp>>1;
- }
- }
- }
-
- void Trace(Rect *baz) {
- PixMapHandle bar = GetGWorldPixMap(gBraveNewGWorld);
- unsigned long rbytes = (bar[0]->rowBytes & 0x3FFF)>>2;
- Ptr data = GetPixBaseAddr(GetGWorldPixMap(gBraveNewGWorld));
- long x, y;
- unsigned long *from, *to;
- unsigned long comp;
- unsigned long *buffer = (unsigned long *)NewPtr( (baz->right - baz->left) * (baz->bottom - baz->top) * 4 );
- Ptr testptr;
-
- testptr = NewPtr(1<<23);
- if(!testptr) {
- DebugStr("\pi couldn't allocate the bigass pointer. you lose");
- } else {
- DisposePtr(testptr);
- }
-
- if(!data) {
- DebugStr("\pthe pixbaseaddr of our gworld is nil");
- return;
- }
-
- if(!buffer) {
- DebugStr("\pthe buffer is nil");
- return;
- }
-
- for(y = baz->top; y < baz->bottom; y++) {
- for(x = baz->left; x < baz->right; x++) {
- from = (unsigned long*)(data + (y * (rbytes<<2)) + (x * 4));
- to = buffer + y*(baz->right - baz->left) + x;
-
- comp =
- ( ( *(from - 1) & 0xFCFCFCFC) >> 2) +
- ( ( *(from + 1) & 0xFCFCFCFC) >> 2) +
- ( ( *(from - rbytes) & 0xFCFCFCFC) >> 2) +
- ( ( *(from + rbytes) & 0xFCFCFCFC) >> 2);
-
- if( ((char*)from)[1] > ((char*)&comp)[1] )
- ((char*)to)[1] = ((char*)from)[1] - ((char*)&comp)[1];
- else
- ((char*)to)[1] = ((char*)&comp)[1] - ((char*)from)[1];
-
- if( ((char*)from)[2] > ((char*)&comp)[2] )
- ((char*)to)[2] = ((char*)from)[2] - ((char*)&comp)[2];
- else
- ((char*)to)[2] = ((char*)&comp)[2] - ((char*)from)[2];
-
- if( ((char*)from)[3] > ((char*)&comp)[3] )
- ((char*)to)[3] = ((char*)from)[3] - ((char*)&comp)[3];
- else
- ((char*)to)[3] = ((char*)&comp)[3] - ((char*)from)[3];
- }
- }
- for(y = baz->top; y < baz->bottom; y++) {
- for(x = baz->left; x < baz->right; x++) {
- *(unsigned long*)(data + (y * (rbytes<<2)) + (x * 4)) = buffer[y*(baz->right - baz->left) + x];
- }
- }
- DisposePtr((char*)buffer);
- }
-
- /*
- * DebugStr() + printf() = very useful function
- */
- void dprintf(char *format, ...) {
- va_list args;
- char dbugstr[256];
-
- va_start(args, format);
- vsprintf(dbugstr, format, args);
- va_end(args);
-
- DebugStr(CtoPstr((char*)dbugstr));
- }
-
- void Right(Rect *baz) {
- PixMapHandle bar = GetGWorldPixMap(gBraveNewGWorld);
- unsigned long rbytes = bar[0]->rowBytes & 0x3FFF;
- Ptr data = GetPixBaseAddr(GetGWorldPixMap(gBraveNewGWorld));
- long x, y;
- unsigned long *pixelptr;
- char foo;
-
- if(!data) {
- DebugStr("\pthe pixbaseaddr of our gworld is nil");
- return;
- }
-
- for(y = baz->top; y < baz->bottom; y++) {
- for(x = baz->left; x < baz->right; x++) {
- pixelptr = (unsigned long*)(data + (y * rbytes) + (x * 4));
- foo = ((char*)pixelptr)[1];
- ((char*)pixelptr)[1] = ((char*)pixelptr)[2];
- ((char*)pixelptr)[2] = ((char*)pixelptr)[3];
- ((char*)pixelptr)[3] = foo;
- }
- }
- }
-
- void Left(Rect *baz) {
- PixMapHandle bar = GetGWorldPixMap(gBraveNewGWorld);
- unsigned long rbytes = bar[0]->rowBytes & 0x3FFF;
- Ptr data = GetPixBaseAddr(GetGWorldPixMap(gBraveNewGWorld));
- long x, y;
- unsigned long *pixelptr;
- char foo;
-
- if(!data) {
- DebugStr("\pthe pixbaseaddr of our gworld is nil");
- return;
- }
-
- for(y = baz->top; y < baz->bottom; y++) {
- for(x = baz->left; x < baz->right; x++) {
- pixelptr = (unsigned long*)(data + (y * rbytes) + (x * 4));
- foo = ((char*)pixelptr)[3];
- ((char*)pixelptr)[3] = ((char*)pixelptr)[2];
- ((char*)pixelptr)[2] = ((char*)pixelptr)[1];
- ((char*)pixelptr)[1] = foo;
- }
- }
- }
-